package cfca.seal.bean;

import cfca.seal.exception.CodeException;
import cfca.seal.util.StringUtil;
import java.util.Date;

public class SealCert extends BaseBean
{
  private String alias;
  private String keyLength = "";
  private String device;
  private String keyId;
  private byte[] p10 = "".getBytes();
  private byte[] publickCertData = "".getBytes();
  private byte[] privateKeyEncryptedData = "".getBytes();
  private String certAlg;
  private String organizationId;
  private String status;
  private Date importDate;
  private String password = "";
  private String privateKeyData = "";
  private String passwordPlain = "";
  private Date notBefore;
  private Date notAfter;
  private String DN;
  private String issuer;
  private Date createTime;

  public String getId()
  {
    return this.id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getAlias() {
    return this.alias;
  }

  public void setAlias(String alias) {
    this.alias = alias;
  }

  public String getOrganizationId() {
    return this.organizationId;
  }

  public void setOrganizationId(String organizationId) {
    this.organizationId = organizationId;
  }

  public String getDevice() {
    return this.device;
  }

  public void setDevice(String device) {
    this.device = device;
  }

  public String getKeyLength() {
    return this.keyLength;
  }

  public void setKeyLength(String keyLength) {
    this.keyLength = keyLength;
  }

  public String getCertAlg() {
    return this.certAlg;
  }

  public void setCertAlg(String certAlg) {
    this.certAlg = certAlg;
  }

  public String getKeyId() {
    return this.keyId;
  }

  public void setKeyId(String keyId) {
    this.keyId = keyId;
  }

  public String getStatus() {
    return this.status;
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public Date getImportDate() {
    return this.importDate;
  }

  public void setImportDate(Date importDate) {
    this.importDate = importDate;
  }

  public Date getNotBefore() {
    return this.notBefore;
  }

  public void setNotBefore(Date notBefore) {
    this.notBefore = notBefore;
  }

  public Date getNotAfter() {
    return this.notAfter;
  }

  public void setNotAfter(Date notAfter) {
    this.notAfter = notAfter;
  }

  public String getDN() {
    return this.DN;
  }

  public void setDN(String dN) {
    this.DN = dN;
  }

  public String getPassword() {
    return this.password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getPrivateKeyData() {
    return this.privateKeyData;
  }

  public void setPrivateKeyData(String privateKeyData) {
    this.privateKeyData = privateKeyData;
  }

  public String getPasswordPlain() {
    return this.passwordPlain;
  }

  public void setPasswordPlain(String passwordPlain) {
    this.passwordPlain = passwordPlain;
  }

  public String getIssuer() {
    return this.issuer;
  }

  public void setIssuer(String issuer) {
    this.issuer = issuer;
  }

  public Date getCreateTime() {
    return this.createTime;
  }

  public void setCreateTime(Date createTime) {
    this.createTime = createTime;
  }

  public byte[] getP10() {
    return this.p10;
  }

  public void setP10(byte[] p10) {
    this.p10 = p10;
  }

  public byte[] getPublickCertData() {
    return this.publickCertData;
  }

  public void setPublickCertData(byte[] publickCertData) {
    this.publickCertData = publickCertData;
  }

  public byte[] getPrivateKeyEncryptedData() {
    return this.privateKeyEncryptedData;
  }

  public void setPrivateKeyEncryptedData(byte[] privateKeyEncryptedData) {
    this.privateKeyEncryptedData = privateKeyEncryptedData;
  }

  public void decryptCiphertext(SealCert sealCert) throws CodeException {
    try {
      if (StringUtil.isNotEmpty(sealCert.getPassword())) {
        sealCert.setPasswordPlain(cfca.seal.util.EncryptUtil.decrypto(sealCert.getPassword()));
      }

      if (null != sealCert.getPrivateKeyEncryptedData()) {
        String privateKeyData = new String(cfca.sadk.util.EncryptUtil.decryptMessageBySM4(sealCert.getPrivateKeyEncryptedData(), sealCert.getPasswordPlain()));

        sealCert.setPrivateKeyData(privateKeyData);
      }
    } catch (Exception e) {
      throw new CodeException("C6005", "解密加密数据失败", e);
    }
  }
}